class ArrayIterator
  def initialize(array=[])
    @array = array
    @idx = 0
  end
  def has_next?()
    @idx < @array.length
  end
  def next()
    old = @idx
    @idx = @idx + 1
    @array[old]
  end
end

def merge_and_sort(arr_one, arr_two)
  return arr_two if (arr_one.nil?() || arr_one.empty?())
  return arr_one if (arr_two.nil?() || arr_two.empty?())
  if arr_one[0] < arr_two[0]
    first = arr_one
    second = arr_two
  else
    first = arr_two
    second = arr_one
  end
  result = []
  total_size = first.size + second.size
  while result.size < total_size
    puts("Result: #{result} \nFirst: #{first} \nSecond: #{second}")
    (result << first; break) if second.empty?
    (result << second; break) if first.empty?
    result << first.shift if  !first.empty? && !second.empty? && first[0] < second[0]
    result << second.shift if !first.empty? && !second.empty? && second[0] < first[0]
  end
  result
end

class Person
  attr_accessor :name
  def initialize(name)
    @name = name
  end
  def <=>(person)
    puts("called with #{person}")
    @name <=> person.name
  end
  def to_s()
    "Person(name=#{name})"
  end
end

class Home
  include Enumerable
  attr_accessor :persons
  def initialize(persons=[])
    @persons = persons
  end
  def add_person(person)
    @persons << person
  end
  def each(&block)
    @persons.each(&block)
  end
end

def main()
  home = Home.new([Person.new('sanjay'), Person.new('Rajiv'), Person.new('Shaku'), Person.new('Tilku')])
  #puts home.any? { |p| p.name.length >= 6 }
  #puts home.include?(Person.new('Rajiv'))
  puts home.min
end

main()

#what should I do to make include?(obj) work?
#Why doesn't objectspace object work even after adding the runtime flag -X+0 ?
